#ifndef Set_First
#define Set_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Collection.h"

class SetIter;
class HashTable;
class RobustHashTable;

//---- Set ---------------------------------------------------------------------

class Set : public Collection {
friend SetIter;
friend RobustHashTable;
public:
	MetaDef(Set);
	Set(int initCapacity= cContainerInitCap);
	~Set();
	void InitNew();
	void Empty(int newCapacity= cContainerInitCap);
	void FreeAll();
	int Capacity();

	//---- manipulation
	Object *Add(Object*);
	Object *Remove(Object*);
	Object *RemovePtr(Object*);

	//---- access
	Iterator *MakeIterator(bool= cIterForward, void *placement= 0);
	Object *Find(Object*);
	Object *FindPtr(Object*);
	int OccurrencesOf(Object*);
	int OccurrencesOfPtr(Object*);

	//---- statistics
	double AverageCollisions();

protected:
	//---- initialization
	Set(Set*);
	void Init(int initCapacity);

	//---- robust iterators
	void SaveItersPosition(int forPix);
	void ResetItersPosition();

protected:
	HashTable *ht;
};

//---- SetIter -----------------------------------------------------------------

class SetIter : public Iterator {
friend Set;
public:
	SetIter(Set *aSet);
	~SetIter();

	Object *operator()();
	void Reset();
protected:
	Container *GetContainer();
	void SavePosition(int pix);
	void ResetPosition();
protected:
	Set *set;
	HashTable *ht;
	int pix;
	Object *saved;
};

//---- IdSet -------------------------------------------------------------------

class IdSet : public Set {
public:
	MetaDef(IdSet);
	IdSet(int initCapacity= cContainerInitCap);
	void InitNew();
protected:
	void Init(int aCapacity);
};

#endif

